<?php
/**
 * FastApp.
 * 7/25/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159
 */

use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateFastappCurrencyTable extends Migration
{
    public function up(): void
    {
        Schema::create('currency', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('币种表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->char('symbol', 32)->nullable()->comment('币种代码');
            $table->char('icon', 64)->nullable()->comment('图标');
            $table->char('address')->nullable()->comment('充值地址/合约地址');
            $table->bigInteger('parent_id')->comment('0主链')->unsigned()->default(0);
            $table->integer('chain_id')->comment('链id')->unsigned()->default(1);
            $table->char('scan_url')->comment('浏览地址')->default('');
            $table->tinyInteger('type')->comment('1法币2加密币3代币')->unsigned()->default(0);
            $table->decimal('withdrawal_min', 18, 6)->comment('最小提币金额')->default(0);
            $table->decimal('withdrawal_max', 18, 6)->comment('最大提币金额')->default(0);
            $table->decimal('withdrawal_charge', 18, 6)->comment('提币手续费')->default(0);
            $table->decimal('deposit_min', 18, 6)->comment('最小质押')->default(0);
            $table->decimal('recharge_min', 18, 6)->comment('最小充值')->default(0);
            $table->decimal('gas_min', 8, 6)->comment('最小gas fee')->default(0);
            $table->tinyInteger('is_deposit')->comment('质押0否1是')->unsigned()->default(0);
            $table->tinyInteger('is_trade')->comment('开启现货交易')->unsigned()->default(0);
            $table->tinyInteger('is_contract')->comment('开启合约交易')->unsigned()->default(0);
            $table->tinyInteger('is_futures')->comment('开启期权交易')->unsigned()->default(0);
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->tinyInteger('is_show')->comment('显示0否1是')->unsigned()->default(1);
            $table->tinyInteger('status')->comment('0下架1正常')->unsigned()->default(1);
            $table->tinyInteger('trade_precision')->comment('交易精度')->unsigned()->default(8);
            $table->tinyInteger('precision')->comment('显示精度')->unsigned()->default(2);
            $table->unique('symbol');
            $table->index('parent_id');
        });
        Schema::create('currency_rate', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('币种汇率表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->bigInteger('currency_id')->unsigned();
            $table->char('symbol', 32);
            $table->decimal('rate', 6)->unsigned();
            $table->unique('symbol');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('currency');
        Schema::dropIfExists('currency_rate');
    }
}